<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>Elasticsearch服务器搭建 | Eetal&#39;s Blog</title>

  <!-- keywords -->
  

  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="欢迎查看Eetal的第六篇博客–Centos7搭建Elasticsearch服务器 部署环境centos7 64位elasticsearch 6.3.0之前一开始用的32位，后来报错elasticsearch6.3版本依赖的X-pack插件不支持32位所以用的64位linux 安装JDKelasticsearch和solr都是基于lucene开发的搜索引擎lucene是用java开发的所以java">
<meta property="og:type" content="article">
<meta property="og:title" content="Elasticsearch服务器搭建">
<meta property="og:url" content="http://eetal.gitee.io/blog/2018/06/21/Elasticsearch服务器搭建/index.html">
<meta property="og:site_name" content="Eetal&#39;s Blog">
<meta property="og:description" content="欢迎查看Eetal的第六篇博客–Centos7搭建Elasticsearch服务器 部署环境centos7 64位elasticsearch 6.3.0之前一开始用的32位，后来报错elasticsearch6.3版本依赖的X-pack插件不支持32位所以用的64位linux 安装JDKelasticsearch和solr都是基于lucene开发的搜索引擎lucene是用java开发的所以java">
<meta property="og:locale" content="default">
<meta property="og:updated_time" content="2018-06-21T08:54:59.731Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Elasticsearch服务器搭建">
<meta name="twitter:description" content="欢迎查看Eetal的第六篇博客–Centos7搭建Elasticsearch服务器 部署环境centos7 64位elasticsearch 6.3.0之前一开始用的32位，后来报错elasticsearch6.3版本依赖的X-pack插件不支持32位所以用的64位linux 安装JDKelasticsearch和solr都是基于lucene开发的搜索引擎lucene是用java开发的所以java">
  
    <link rel="alternative" href="/atom.xml" title="Eetal&#39;s Blog" type="application/atom+xml">
  
  
    <link rel="icon" href="http://www.yangyitao.top/FiveChess/resource/ico/favicon.ico">
  
  <link rel="stylesheet" href="/blog/css/style.css">
  
  

  <script src="//cdn.bootcss.com/require.js/2.3.2/require.min.js"></script>
  <script src="//cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>

  
</head>
<body>
  <div id="container">
    <div id="particles-js"></div>
    <div class="left-col">
    <div class="overlay"></div>
<div class="intrude-less">
	<header id="header" class="inner">
		<a href="/" class="profilepic">
			
			<img lazy-src="/blog/images/head.jpg" class="js-avatar">
			
		</a>

		<hgroup>
		  <h1 class="header-author"><a href="/">Eetal</a></h1>
		</hgroup>

		
		<p class="header-subtitle">java coder</p>
		

		
			<div class="switch-btn">
				<div class="icon">
					<div class="icon-ctn">
						<div class="icon-wrap icon-house" data-idx="0">
							<div class="birdhouse"></div>
							<div class="birdhouse_holes"></div>
						</div>
						<div class="icon-wrap icon-ribbon hide" data-idx="1">
							<div class="ribbon"></div>
						</div>
						
						<div class="icon-wrap icon-link hide" data-idx="2">
							<div class="loopback_l"></div>
							<div class="loopback_r"></div>
						</div>
						
						
					</div>
					
				</div>
				<div class="tips-box hide">
					<div class="tips-arrow"></div>
					<ul class="tips-inner">
						<li>菜单</li>
						<li>标签</li>
						
						<li>友情链接</li>
						
						
					</ul>
				</div>
			</div>
		

		<div class="switch-area">
			<div class="switch-wrap">
				<section class="switch-part switch-part1">
					<nav class="header-menu">
						<ul>
						
							<li><a href="/blog/">Home</a></li>
				        
							<li><a href="/blog/archives">Archives</a></li>
				        
						</ul>
					</nav>
					<nav class="header-nav">
						<div class="social">
							
						</div>
					</nav>
				</section>
				
				
				<section class="switch-part switch-part2">
					<div class="widget tagcloud" id="js-tagcloud">
						
					</div>
				</section>
				
				
				
				<section class="switch-part switch-part3">
					<div id="js-friends">
					
			          <a target="_blank" class="main-nav-link switch-friends-link" href="https://github.com/smackgg/hexo-theme-smackdown">smackdown</a>
			        
			        </div>
				</section>
				

				
			</div>
		</div>
	</header>				
</div>
    </div>
    <div class="mid-col">
      <nav id="mobile-nav">
  	<div class="overlay">
  		<div class="slider-trigger"></div>
  		<h1 class="header-author js-mobile-header hide">Eetal</h1>
  	</div>
	<div class="intrude-less">
		<header id="header" class="inner">
			<div class="profilepic">
				<img lazy-src="/blog/images/head.jpg" class="js-avatar">
			</div>
			<hgroup>
			  <h1 class="header-author">Eetal</h1>
			</hgroup>
			
			<p class="header-subtitle">java coder</p>
			
			<nav class="header-menu">
				<ul>
				
					<li><a href="/blog/">Home</a></li>
		        
					<li><a href="/blog/archives">Archives</a></li>
		        
		        <div class="clearfix"></div>
				</ul>
			</nav>
			<nav class="header-nav">
				<div class="social">
					
				</div>
			</nav>
		</header>				
	</div>
</nav>
      <div class="body-wrap"><article id="post-Elasticsearch服务器搭建" class="article article-type-post" itemscope itemprop="blogPost">
  
    <div class="article-meta">
      <a href="/blog/2018/06/21/Elasticsearch服务器搭建/" class="article-date">
  	<time datetime="2018-06-21T07:02:15.442Z" itemprop="datePublished">2018-06-21</time>
</a>
    </div>
  
  <div class="article-inner">
    
      <input type="hidden" class="isFancy" />
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      Elasticsearch服务器搭建
      
    </h1>
  

      </header>
      
      <div class="article-info article-info-post">
        
        

        
        <div class="clearfix"></div>
      </div>
      
    
    <div class="article-entry" itemprop="articleBody">
      
        <p>欢迎查看Eetal的第六篇博客–Centos7搭建Elasticsearch服务器</p>
<h2 id="部署环境"><a href="#部署环境" class="headerlink" title="部署环境"></a>部署环境</h2><p>centos7 64位<br>elasticsearch 6.3.0<br>之前一开始用的32位，后来报错<br>elasticsearch6.3版本依赖的X-pack插件不支持32位<br>所以用的64位linux</p>
<h2 id="安装JDK"><a href="#安装JDK" class="headerlink" title="安装JDK"></a>安装JDK</h2><p>elasticsearch和solr都是基于lucene开发的搜索引擎<br>lucene是用java开发的<br>所以java环境是必须的<br>而且elasticsearch6.3.0版本依赖的java版本应该是1.8+的<br>下载对应linux版本的jdk<br><a href="http://www.oracle.com/technetwork/java/javase/downloads/index.html" target="_blank" rel="noopener">http://www.oracle.com/technetwork/java/javase/downloads/index.html</a><br>window发送文件到linux可以使用xshell，securityCRT等SSH连接工具<br>解压文件，-C指定解压目录<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ tar zxf jdk-xxx.tar.gz -C /usr</span><br></pre></td></tr></table></figure></p>
<h2 id="配置java环境变量"><a href="#配置java环境变量" class="headerlink" title="配置java环境变量"></a>配置java环境变量</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ vi /etc/profile</span><br></pre></td></tr></table></figure>
<p>在末尾添加<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">JAVA_HOME=/usr/jdk1.8.0_171</span><br><span class="line">PATH=$JAVA_HOME/bin:$PATH</span><br><span class="line">CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar</span><br><span class="line">export JAVA_HOME</span><br><span class="line">export PATH</span><br><span class="line">export CLASSPATH</span><br></pre></td></tr></table></figure></p>
<p>生效环境配置<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ <span class="built_in">source</span> /etc/profile</span><br></pre></td></tr></table></figure></p>
<p>输入<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ java</span><br></pre></td></tr></table></figure></p>
<p>可以看到相关命令提示就是安装成功了</p>
<h2 id="安装elasticsearch"><a href="#安装elasticsearch" class="headerlink" title="安装elasticsearch"></a>安装elasticsearch</h2><p>下载elasticsearch<br><a href="https://www.elastic.co/downloads/elasticsearch" target="_blank" rel="noopener">https://www.elastic.co/downloads/elasticsearch</a><br>解压文件<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ tar zxf elasticsearch-xxx.tar.gz -C /usr</span><br></pre></td></tr></table></figure></p>
<h2 id="运行elasticsearch"><a href="#运行elasticsearch" class="headerlink" title="运行elasticsearch"></a>运行elasticsearch</h2><p>这一步坑比较多<br>进入解压后的文件夹的bin目录<br>运行elasticsearch<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ ./elasticsearch</span><br></pre></td></tr></table></figure></p>
<p>咔~报错一大堆<br>首先,出于安全考虑，elasticsearch设置了不能以root用户运行<br>ok,创建一个新用户elasticsearch并配置密码<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ useradd elasticsearch</span><br><span class="line">$ passwd elasticsearch</span><br></pre></td></tr></table></figure></p>
<p>并指定这个用户加入一个es用户角色群组<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ groupadd es</span><br><span class="line">$ usermod -a -G es elasticsearch</span><br></pre></td></tr></table></figure></p>
<p>切换到新创建的elasticsearch用户<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ su elasticsearch</span><br></pre></td></tr></table></figure></p>
<p>在运行一遍~<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ ./elasticsearch</span><br></pre></td></tr></table></figure></p>
<p>咔~报错更多了<br>提示access denied<br>权限不够(~~)<br>没办法，很大一部分文件权限都是root才有<br>所以我们应该给es群组授权<br>切换到root<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ su root</span><br></pre></td></tr></table></figure></p>
<p>指定解压的elasticsearch的文件夹的拥有者及群组<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ chown -R elasticsearch:es elasticsearch-6.3.0/</span><br></pre></td></tr></table></figure></p>
<p>切回elasticsearch用户并运行<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ su elasticsearch</span><br><span class="line">$ ./elasticsearch</span><br></pre></td></tr></table></figure></p>
<p>咔~<br>这一步因系统而异了，因为涉及到linux的一些默认配置<br>比如单个文件最大大小<br>最多线程数量这些<br>如果报错<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">bootstrap checks failed</span><br><span class="line"></span><br><span class="line">max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]</span><br><span class="line">max number of threads [1024] for user [elasticsearch] likely too low, increase to at least [4096]</span><br><span class="line">max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]</span><br></pre></td></tr></table></figure></p>
<p>切换到root用户<br>修改linux默认配置<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ su root</span><br><span class="line">$ vi /etc/security/limits.conf</span><br></pre></td></tr></table></figure></p>
<p>在末尾添加<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">@es soft nofile 65536</span><br><span class="line"></span><br><span class="line">@es hard nofile 131072</span><br><span class="line"></span><br><span class="line">@es soft nproc 4096</span><br><span class="line"></span><br><span class="line">@es hard nproc 4096</span><br></pre></td></tr></table></figure></p>
<p>第一个参数可以是用户名也可以是一个 @群组名<br>分别代表对一个用户授权或者对一个群组授权<br>接下来<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ vi /etc/sysctl.conf</span><br></pre></td></tr></table></figure></p>
<p>在末尾添加<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vm.max_map_count=655360</span><br></pre></td></tr></table></figure></p>
<p>生效配置<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ sysctl -p</span><br></pre></td></tr></table></figure></p>
<p>至此，elasticsearch可以正常运行</p>
<h2 id="测试elasticsearch服务"><a href="#测试elasticsearch服务" class="headerlink" title="测试elasticsearch服务"></a>测试elasticsearch服务</h2><p>运行elasticsearch服务后，我们打开浏览器<br>访问<a href="http://es服务器ip:9200" target="_blank" rel="noopener">http://es服务器ip:9200</a><br>还是访问不了<br>1.linux防火墙<br>先开启linux防火墙<br>ctrl+c取消运行elasticsearch服务后<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">$ su root</span><br><span class="line">$ firewall-cmd --zone=public --add-port=9200/tcp --permanent</span><br><span class="line">$ firewall-cmd --reload</span><br></pre></td></tr></table></figure></p>
<p>–permanent参数代表永久开放，没有该参数则重启机器后端口不开放<br>此时运行elasticsearch<br>还是访问不了<br>2.修改elasticsearch.yml中的配置<br>出于安全起见<br>elasticsearch默认只允许本机localhost访问<br>修改elasticsearch的配置文件，允许别的ip访问<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ vi config/elasticsearch.yml</span><br></pre></td></tr></table></figure></p>
<p>在末尾增加<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">network.host: 0.0.0.0</span><br></pre></td></tr></table></figure></p>
<p>0.0.0.0代表所有ip都可以访问<br>文件中还可以设置自定义日志、数据目录，此处不再啰嗦<br>至此，重启elasticsearch<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ ./elasticsearch</span><br></pre></td></tr></table></figure></p>
<p>打开浏览器访问<br><a href="http://es服务器ip:9200" target="_blank" rel="noopener">http://es服务器ip:9200</a><br>可以看到返回的elasticsearch相关信息<br>完成部署</p>
<h3 id="更多精彩内容"><a href="#更多精彩内容" class="headerlink" title="更多精彩内容"></a>更多精彩内容</h3><h3 id="请移步"><a href="#请移步" class="headerlink" title="请移步"></a>请移步</h3><p>个人主页: <a href="http://yangyitao.top" target="_blank" rel="noopener">yangyitao.top</a></p>

      
    </div>
    
  </div>
  
    
<nav id="article-nav">
  
    <a href="/blog/2018/07/17/SpringBootCache/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">&lt;</strong>
      <div class="article-nav-title">
        
          SpringBoot在同一类中方法内部调用缓存方法Cacheable注解无效的问题
        
      </div>
    </a>
  
  
    <a href="/blog/2018/06/12/python网络爬虫并输出excel/" id="article-nav-older" class="article-nav-link-wrap">
      <div class="article-nav-title">Python网络爬虫并输出到excel</div>
      <strong class="article-nav-caption">&gt;</strong>
    </a>
  
</nav>

  
</article>


<div class="ds-share share" data-thread-key="Elasticsearch服务器搭建" data-title="Elasticsearch服务器搭建" data-url="http://eetal.gitee.io/blog/blog/2018/06/21/Elasticsearch服务器搭建/"  data-images="/blog/images/head.jpg" data-content="Elasticsearch服务器搭建">
    <div class="ds-share-inline">
      <ul  class="ds-share-icons-16">
      	<li data-toggle="ds-share-icons-more"><a class="ds-more" href="javascript:void(0);">分享到：</a></li>
        <li><a class="ds-weibo" href="javascript:void(0);" data-service="weibo">微博</a></li>
        <li><a class="ds-qzone" href="javascript:void(0);" data-service="qzone">QQ空间</a></li>
        <li><a class="ds-qqt" href="javascript:void(0);" data-service="qqt">腾讯微博</a></li>
        <li><a class="ds-wechat" href="javascript:void(0);" data-service="wechat">微信</a></li>
      </ul>
      <div class="ds-share-icons-more">
      </div>
    </div>
 </div>
 





</div>
      <footer id="footer">
  <div class="outer">
    <div id="footer-info">
      <div class="footer-left">
        &copy; 2019 Eetal
      </div>
        <div class="footer-right">
          <a href="http://hexo.io/" target="_blank">Hexo</a>  Theme <a href="https://github.com/smackgg/hexo-theme-smackdown" target="_blank">Smackdown</a>
        </div>
    </div>
  </div>
</footer>
    </div>
    
  <link rel="stylesheet" href="/blog/fancybox/jquery.fancybox.css">


<script>
	var yiliaConfig = {
		fancybox: true,
		mathjax: true,
		animate: true,
		isHome: false,
		isPost: true,
		isArchive: false,
		isTag: false,
		isCategory: false,
		open_in_new: false
	}
</script>
<script src="/blog/js/main.js"></script>



<script type="text/x-mathjax-config">
MathJax.Hub.Config({
    tex2jax: {
        inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
        processEscapes: true,
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
    }
});

MathJax.Hub.Queue(function() {
    var all = MathJax.Hub.getAllJax(), i;
    for(i=0; i < all.length; i += 1) {
        all[i].SourceElement().parentNode.className += ' has-jax';                 
    }       
});
</script>

<script src="//cdn.bootcss.com/mathjax/2.7.0/MathJax.js"></script>


  </div>
</body>
</html>